<template>
	<view class="">
		<view class="utop" :style="{'padding-top':statusBarHeight+'px'}">
			<view class="u_left">
				<view class="u_left" @click="open">
					<image class="uimg" :src="userInfo.avatar" mode=""></image>
					<view class="texts">
					    {{userInfo.nickname}}
					</view>
					<!-- ,1=吸塑,2=圆磨,3=洗片,4=下钻 -->
					<view class="tag" v-if="userInfo.type == 1">吸塑</view>
					<view class="tag" v-if="userInfo.type == 2">圆磨</view>
					<view class="tag" v-if="userInfo.type == 3">洗片</view>
					<view class="tag" v-if="userInfo.type == 4">下钻</view>
				</view>
				<image @click="sm" v-if="istype == 1" class="usmimg" src="../../static/icon3.png" mode=""></image>
			</view>
		</view>
		<view class="" :style="{'height':statusBarHeight+45+'px'}"></view>
		<uni-popup ref="popup" type="center">
			<view class="outlogin">
				<uni-icons class="icon" type="closeempty" size="20" @click="close"></uni-icons>
				<view class="ucont">
					<image class="uimg" :src="userInfo.avatar" mode=""></image>
					<view class="uflex">
						<view class="texts">
							{{userInfo.nickname}}
						</view>
						<view class="">
							<view class="tag" v-if="userInfo.type == 1">吸塑</view>
							<view class="tag" v-if="userInfo.type == 2">圆磨</view>
							<view class="tag" v-if="userInfo.type == 3">洗片</view>
							<view class="tag" v-if="userInfo.type == 4">下钻</view>
						</view>
					</view>
				</view>
				<view class="btn" @click="outlogin">
					退出登录
				</view>
				<view class="" style="height: 20rpx;">
					
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		props: {
			istype: {
				type: Number,
				default: 0
			}
		},
		name: "utop",
		data() {
			return {
				statusBarHeight: uni.getStorageSync('statusBarHeight'),
				userInfo:uni.getStorageSync('userinfo'),
				id:0
			};
		},
		created() {
		},
		methods: {
			sm(){
				let that = this
				uni.scanCode({
					barCodeInput: true,
					onlyFromCamera: true,
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
				           that.id = res.path.substring( res.path.lastIndexOf('?') + 1,res.path.length).substring(9)
						   setTimeout(()=>{
							   that.handleSm()
						   },500)
						}
					},
				})
			},
			handleSm() {
				if(this.userInfo.type == 1){
					uni.redirectTo({
						url:`/pages/index/xspage?id=${this.id}`
					})
				}
				if(this.userInfo.type == 2){
					uni.redirectTo({
						url:`/pages/index/ympage?id=${this.id}`
					})
				}
				if(this.userInfo.type == 3){
					uni.redirectTo({
						url:`/pages/index/xppage?id=${this.id}`
					})
				}
				if(this.userInfo.type == 4){
					uni.redirectTo({
						url:`/pages/index/xzpage?id=${this.id}`
					})
				}
			
			},
			open() {
				this.$refs.popup.open()
			},
			close(){
				this.$refs.popup.close()
			},
			outlogin(){
				uni.showLoading({
					title: '安全退出中',
					mask: true
				})
				setTimeout(()=>{
					uni.reLaunch({
						url:'/pages/login/login'
					})
				},500)
			}
		}
	}
</script>

<style lang="scss">
	.utop {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		padding: 0rpx 20rpx;
		display: flex;
		align-items: center;
		position: fixed;
		z-index: 9;
		background-color: #fff;
		top: 0%;

		.u_left {
			display: flex;
			align-items: center;

			.uimg {
				width: 60rpx;
				height: 60rpx;
				border-radius: 30rpx;
			}

			.texts {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #1D2541;
				margin-left: 20rpx;
				white-space:nowrap;
				overflow:hidden;
				text-overflow:ellipsis;
				max-width: 160rpx;
			}

			.tag {
				width: 74rpx;
				height: 36rpx;
				background: #1246C8;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 36rpx;
				text-align: center;
				margin: 0rpx 20rpx;
			}
		}

		.usmimg {
			width: 46rpx;
			height: 46rpx;
		}

	}

	.outlogin {
		width: 560rpx;
		background: #FFFFFF;
		border-radius: 30rpx;
		.icon {
			position: absolute;
			right: 30rpx;
			top: 30rpx;
		}

		.ucont {
			text-align: center;
			padding-top: 66rpx;
		}

		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #1D2541;
			white-space:nowrap;
			overflow:hidden;
			text-overflow:ellipsis;
			max-width: 260rpx;
		}
		.uflex {
			align-items: center;
			margin: 20rpx auto;
			text-align: center;
			display: flex;
			justify-content: center;
		}

		.uimg {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50rpx;
		}

		.tag {
			background: #1246C8;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 24rpx;
			color: #FFFFFF;
			line-height: 36rpx;
			text-align: center;
			margin: 0rpx 20rpx;
			padding: 4rpx 14rpx;
		}
		.btn{
			width: 360rpx;
			height: 80rpx;
			background: #FFFFFF;
			border-radius: 40rpx;
			margin: 60rpx auto;
			text-align: center;
			line-height: 78rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #979797;
			border: 1rpx solid #979797;
		}
	}
</style>